<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    String deptId =  request.getParameter("deptId");
%>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link href="<%=basePath %>bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="<%=basePath %>bootstrap/bootstrap-table/dist/bootstrap-table.css" rel="stylesheet"/>
    <script src="<%=basePath %>bootstrap/js/jquery.min.js"></script>
    <script src="<%=basePath %>bootstrap/js/bootstrap.min.js"></script>
    <script src="<%=basePath %>bootstrap/bootstrap-table/dist/bootstrap-table.min.js"></script>
    <script src="<%=basePath %>bootstrap/bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="<%=basePath %>bootstrap/bootbox/bootbox.min.js"></script>
    <script src="<%=basePath %>bootstrap/commend/initcommend.js"></script>
</head>
<body>

<div class="col-md-12" >
    <div id="toolbar" class="btn-group">
        <button id="btn_save" type="button" class="btn btn-default " data-toggle="modal" data-target="#modalTable" style="margin-right: 10px">
            <span class="glyphicon " aria-hidden="true">绑定调查问卷</span>
        </button>
        <button id="btn_back" type="button" class="btn btn-default " >
            <span class="glyphicon " aria-hidden="true">返回</span>
        </button>
    </div>
    <table
            id="table"
            data-toggle="table"
            data-search="true"
            data-click-to-select="true"
            data-toolbar="#toolbar"
            data-url="../deptMapper/selectEvalDeptByDeptId?deptId=${deptid}"
            class="col-md-12">
        <thead>
        <tr>
            <th data-field="state" data-checkbox="true"></th>
            <th data-field="code">科室代码</th>
            <th data-field="name">科室名称</th>
            <th data-field="papername">绑定调查问卷</th>
        </tr>
        </thead>
    </table>
</div>

<div class="modal fade" id="modalTable" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">评价问卷表</h4>
            </div>
            <div class="modal-body">
                <table id="papertable"
                       data-toggle="table"
                       data-height="299"
                       data-single-select="true"
                       data-click-to-select="true"
                       data-url="../testPaper/selectAllPaper" style="table-layout: fixed;">
                    <thead>
                    <tr>
                        <th data-checkbox="true"></th>
                        <th data-field="name" >调查问卷名称</th>
                        <th data-field="mark">描述</th>
                    </tr>
                    </thead>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"  id="btn_sure">确定</button>
            </div>
        </div>
    </div>
</div>
<script>

    $(function() {
        $('#modalTable').on('shown.bs.modal', function () {
            $("#papertable").bootstrapTable('resetView')
        })
        
        $("#btn_back").on('click',function () {
            window.location.href = getRootPath_web() + '/jsp/adminpaper.jsp'
        })

        $("#btn_sure").on('click',function () {
            var evaldeptrows =  $("#table").bootstrapTable('getSelections')
            var paperrows =  $("#papertable").bootstrapTable('getSelections')
            var evaldeptid = '';
            var paperid = '';
            $(paperrows).each(function () {
                paperid = this.paperId;
            })
            $(evaldeptrows).each(function () {
                evaldeptid += this.code;
                evaldeptid += ',';
            })
            $.post(getRootPath_web()+'/testPaper/addEvalDeptPaper',{
                deptcode:${deptid},
                evalDeptCodeString:evaldeptid,
                papaerId:paperid
            },function (data) {
                if(data){
                    $('#modalTable').modal('hide')
                    bootbox.alert("绑定成功",function () {
                        $("#table").bootstrapTable('refresh')
                    });
                }else{
                    $('#modalTable').modal('hide')
                    bootbox.alert("绑定失败");

                }
            },'json')
        })

    })
</script>
</body>

</html>